/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bsc.bscpb;

import com.bsc.logs.util.LoadLogback;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 *
 * @author Administrator
 */
public class SysControl {

    static Logger LOGGER = LoggerFactory.getLogger(SysControl.class);
    private static SysControl instance = null;
    private NioSocketAcceptor nsa = null;
    private ApplicationContext act = null;

    public synchronized static SysControl getInstance() {
        if (instance == null) {
            instance = new SysControl();
        }
        return instance;
    }

    private SysControl() {
    }

    public void Start() {
        try {
//            new LockThread().start();
            System.out.println("++++++++++++++++++++加载日志模块++++++++++++++++++++");
            new LoadLogback("/com/bsc/logs/logback/logback.xml");
            System.out.println("++++++++++++++++++++日志模块加载完毕++++++++++++++++++++");
            System.out.println("++++++++++++++++++++加载Spring配置文件++++++++++++++++++++");
            act = new FileSystemXmlApplicationContext(SysControl.class.getResource("/com/bsc/bscpb/spring/applicationContext.xml").toString());
            String names[] = act.getBeanDefinitionNames();
            LOGGER.info("已加载Bean总量：" + names.length);
            for (String name : names) {
                LOGGER.info("已加载Bean：" + name);
            }
            System.out.println("++++++++++++++++++++Spring配置文件加载完毕++++++++++++++++++++");
            System.out.println("");
            System.out.println("");
            nsa = (NioSocketAcceptor) act.getBean("ioAcceptor");
            if (nsa != null && nsa.isActive()) {
                LOGGER.info("Mina服务启动: " + nsa.getDefaultLocalAddress().getHostName() + ":" + nsa.getDefaultLocalAddress().getPort());
            }
            System.out.println("++++++++++++++++++++服务启动完毕++++++++++++++++++++");
            while (true) {
            }
        } catch (Exception e) {
            System.out.println("++++++++++++++++++++启动错误++++++++++++++++++++");
            System.out.println(e.getLocalizedMessage());
            System.exit(0);
        }
    }

    public void Stop() {
        System.out.println("System stop!!");
    }
}
